#include <iostream>
#include "circularbuffer1.h"
#include "circularbuffer2.h"
#include "circularbuffer3.h"
#include "circularbuffer4.h"
#include "producer.h"
#include "consumer.h"
#include <stdlib.h>
#include <pthread.h>

// void *foo(void* args){
//  while(1)
//     {
// 	int datum = (int)(rand() * 100000);
// 	output->put(datum);
// 	std::cout << "Put" << datum << std::endl;
// 	usleep((long)rand()*2000);
//     }
//     return &args; 
// }

// void* run(void* args)
// {
//     std::cout << "im Thread" << std::endl;
//     producer* p = (producer*) args;
//     
//     while(1)
//     {
// 	int datum = (int)(rand() % 100000+1);
// 	p->output->put(datum);
// 	std::cout << "Put " << datum << std::endl;
// 	usleep((long)rand()%2000);
//     }
//     int* i;
//     *i = 12;
//     return i;
// }

int main(int argc, char **argv) {
    srand(122452);
    std::cout << "Hello, CircularBuffer 1!" << std::endl;
    circularbuffer2* buf = new circularbuffer2();
    
    pthread_t thread1;
    pthread_t thread2;
    int retValue;
    
   
    
    producer* p = new producer(buf);
    consumer* c = new consumer(buf);
    
    int ret;
    ret = p->createThread(&thread1);
    
    ret = c->createThread(&thread2);
    
    p->join(thread1);
    c->join(thread2);
    //p->join(thread1);
    
    
    //int ret = pthread_create(&thread1, &attr, p->run, p);
    
    //pthread_join(thread1, NULL);
    //std::cout << "Fehler Producer" << ret<< std::endl;
    
    return 0;
}

